Hyper is a rock solid Rust HTTP client and server toolkit.
Unix domain sockets provide a mechanism
for host-local interprocess communication. hyperlocal
builds on and complements Hyper's
interfaces for building Unix domain socket HTTP clients and servers.
This is useful for exposing simple HTTP interfaces for your Unix daemons in cases where you want to limit access to the current host, in which case, opening and exposing tcp ports is not needed. Examples of Unix daemons that provide this kind of host local interface include Docker, a process container manager.
Installation
Add the following to your Cargo.toml
file
[]
= "0.8"
Usage
Servers
A typical server can be built with hyperlocal::server::UnixServerExt
.
use ;
use ;
use UnixServerExt;
const PHRASE: &str = "It's a Unix system. I know this.";
async
To test that your server is working you can use an out of the box tool like curl
Clients
hyperlocal
also provides bindings for writing unix domain socket based HTTP clients using Hyper
's native Client
interface.
Configure your Hyper
client using hyper::Client::builder()
.
Hyper's client interface makes it easy to send typical HTTP methods like GET
, POST
, DELETE
with factory
methods, get
, post
, delete
, etc. These require an argument that can be tranformed into a hyper::Uri
.
Since Unix domain sockets aren't represented with hostnames that resolve to ip addresses coupled with network ports,
your standard over the counter URL string won't do. Instead, use a hyperlocal::Uri
, which represents both file path to the domain
socket and the resource URI path and query string.
use Error;
use ;
use ;
use ;
async
Doug Tangren (softprops) 2015-2020